package team.jaman.autosell.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import team.jaman.autosell.entity.Orders;
import team.jaman.autosell.service.OrdersService;
import team.jaman.autosell.tools.CommonData;
import team.jaman.autosell.tools.OrdersCount;
import team.jaman.autosell.tools.PageData;
import team.jaman.autosell.tools.Param;

/**
 * 订单控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping("orders")
public class OrdersController {
 
	@Autowired
	private OrdersService ordersService;
	
	/**
	 * 订单列表信息
	 * @param page 当前页
	 * @param limit 每页记录数
	 * @param userkeyword 用户名关键字
	 * @return
	 */
	@GetMapping("showOrdersList")
	@ResponseBody
	public PageData<Orders> selectOrdersByLikeUserName(@RequestParam(value="page",defaultValue="1") int page, @RequestParam(value="limit",defaultValue="10") int limit, @RequestParam(value="userkeyword",defaultValue="") String userkeyword){
		return ordersService.getOrdersByLike(page, limit, userkeyword);
	}
	
	/**
	 * 下单
	 * @param param 下单信息封装类
	 * @return 下单提示信息
	 */
	@PostMapping("payorders")
	@ResponseBody
	public CommonData getpayorders(@RequestBody Param param) {
		// 判断
		boolean flag = ordersService.insertOrders(param);
		CommonData commonData = new CommonData();
		if(flag) {
			commonData.setMsg("下单成功");
		} else {
			commonData.setMsg("下单失败");
		}
		return commonData;
	}
	
	/**
	 * 查询日订单统计
	 * @return
	 */
	@GetMapping("countDay")
	@ResponseBody
	public List<OrdersCount> selectOrdersCountDay(){
		
		
		return ordersService.selectOrdersCountDay() ;
	}
	
	/**
	 * 查询月订单统计
	 * @return
	 */
	@GetMapping("countMonth")
	@ResponseBody
	public List<OrdersCount> selectOrdersCountMonth(){
		
		
		return ordersService.selectOrdersCountMonth() ;
	}
	
	/**
	 * 用户订单列表信息
	 * @param page 当前页
	 * @param limit 每页记录数
	 * @param userkeyword 用户名关键字
	 * @return
	 */
	@GetMapping("showOrdersByUsers")
	@ResponseBody
	public List<Orders> selectOrdersByUser(int userId){
		return ordersService.getOrdersByUser(userId);
	}
}
